#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>

void Swap(int* a, int* b)
{
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

void SelectSort(int* a, int n)
{
	int begin = 0;
	int end = n - 1;

	while (begin < end)
	{
		int min = 0, max = 0;
		for (int i = begin + 1; i <= end; i++)
		{
			if (a[i] < a[min])
			{
				min = i;
			}
			if (a[i] > a[max])
			{
				max = i;
			}
		}
		Swap(&a[min], &a[begin]);
		Swap(&a[max], &a[end]);
		++begin;
		--end;
	}
}

int main()
{
	int a[] = { 12, 23, 45, 3, 26, 1 };
	int size = sizeof(a) / sizeof(int);

	for (int i = 0; i < size; i++)
	{
		printf("%d ", a[i]);
	}
	printf("\n");
	SelectSort(a, size);

	for (int i = 0; i < size; i++)
	{
		printf("%d ", a[i]);
	}

	return 0;
}